package com.jl.security;


import com.jl.card.JL;
import com.jl.security.checksum.ALG_ISO3309_CRC16;
import com.jl.security.checksum.ALG_ISO3309_CRC32;
import com.jl.security.checksum.IChecksum;

public class Checksum {
	
	static{
		Crypto.init();
	}

	public static byte[] checksum(String name, byte[] value, int off, int len,
			int baseValue) {
		IChecksum che = getInstance(name);
		return che.claculat(value, off, len, baseValue);
	}

	private static IChecksum getInstance(String name) {
		if (name.trim().equalsIgnoreCase(JL.CRC16_ISO3309)) {
			return new ALG_ISO3309_CRC16();
		}
		if (name.trim().equalsIgnoreCase(JL.CRC32_ISO3309)) {
			return new ALG_ISO3309_CRC32();
		}
		throw new RuntimeException(name + " not found");
	}
}
